﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class admin_xtgly_tjgly : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin_id"] == null)
        {
            Response.Redirect("admin_logout.aspx");
            return;
        }
    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        string name = this.tbName.Text.Trim();
        string password = this.tbPwd.Text.Trim();
        string conpassword = this.conPwd.Text.Trim();
        string e_mail = this.e_mail.Text.Trim();
        string tel = this.tel.Text.Trim();
        bool bl = false;
        int created_by;
        int count;
        AdminBT at = new AdminBT();
        DataTable dt = at.FindbyName(name);
        if (dt ==null )
        {
            count = -1;
        }
        else if (dt.Rows .Count ==0)
        {
            count = 0;
        }
        else 
        {
            count = 1;
        }
        if (name.Trim().Length == 0)
        {
            this.lb1.Text = "用户名不能为空";
            return;
        }
        else if (count == 1)
        {
            this.lb1.Text = "用户名已被占用，请重新选择";
            return;
        }
        else if(count==-1)
        {
            this.lb1.Text = "判断用户名是否存在失败，逻辑错误";
        }
        else if (password.Trim().Length == 0)
        {
            this.lb2.Text = "密码不能为空";
            return;
        }
        else if (password != conpassword)
        {
            this.lb3.Text = "两次密码输入不一致";
            return;
        }
        else
        {

            created_by = int.Parse(Session["admin_id"].ToString());
            bl = at.InsertAdmin(name, password, created_by, e_mail, tel);
        }
        if (bl)
        {
            message_show("添加成功");
            return;
        }
        else
        {
            message_show("操作失败");
            return;
        }

    }

    /// <summary>
    /// 信息提示
    /// </summary>
    /// <param name="msg">提示信息</param>
    private void message_show(string msg)
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "信息提示", "<script language='javascript'>  warning('" + msg + "');</script>");
    }
}
